﻿Ext.namespace("Swfu");
Ext.namespace("Swfu.BackMgr.mainview");

GongGao = new Ext.grid.GridPanel(
{
    id: 'noticeGrid', border: false, store: GGstore = new Ext.data.Store(
    {
        url: '/File.mvc/GetLatestNotices', reader: new Ext.data.JsonReader(
        {
            id: 'noticeReader', fields: ["Id", "Pid", "Name", "Type", "RealName", "Size", "CreatTime", "OwnerId", "FileClass", "OrderNo", "LastUpdateTime", "LastUpdaterId", "StatusId"]
        })
    }), columns: [
    {
        header: '标题', width: 360, dataIndex: 'Name',
        renderer: function (value, cellmeta, currRow) {
            var title = value;
            var retStr = "<a href='FileViewer.htm?FileClass=2&docRealName=" + currRow.data.RealName + "' target='_blank' onclick='return DocUsedLog(" + currRow.data.Id + ",0);'>" + title + "</a>";
            if (currRow.data.StatusId == 0) {
                retStr = "<img src='../Content/images/home/zuixindongtai.gif' width='28px' height='14px'>" + retStr;
            } else {
                retStr = "<img src='../Content/images/home/news6.gif' width='14px' height='14px'>" + retStr;
            }
            return retStr;
        }
    },
    {
        header: '时间', hidden: false, dataIndex: 'CreatTime',
        renderer: function (value) {
            return DateParseWithoutTime(value);
        }
    }], autoHeight: true, hideHeaders: true, loadMask: true
});
GGstore.load();

DaiDu = new Ext.grid.GridPanel(
{
    id: 'daiDuGrid', border: false,store: DDStore = new Ext.data.Store(
    {
        url: '/File.mvc/GetUnReaded', reader: new Ext.data.JsonReader(
        {
            id: 'daiDuReader', fields: ["Id", "Name", "Type", "RealName", "OwnerId", "Pid", "AuthDate", "AuthLevel", "OriAuthor", "From"]
        })
    }), columns: [
    {
        header: '文件名称', width:305,dataIndex: 'Name',
        renderer: function (value, cellmeta, currRow) {
            return "<img src='../Content/images/home/news6.gif' width='14px' height='14px'><a href='FileDownload.aspx?fileId=" + currRow.data.Id + "' target='_blank' onclick='return DocUsedLog(" + currRow.data.Id + ",0);'>" + value + "</a>";
        }
    }, {
        header: '作者', width: 60, dataIndex: 'OriAuthor'
    }, {
        header: '授权时间',hidden: false, dataIndex: 'AuthDate',
        renderer: function (value) {
            return DateParseWithoutTime(value);
        }
    }, {
        header: "操作",
        dataIndex: "Id",
        renderer: function (value, cellmeta, currRow, b, c, d, e, f, g) {
            var returnArr = [];
            if (currRow.data.Type != 'dir') {
                var filePath = "PersonalFolder\\";
                if ('doc,xls'.indexOf(currRow.data.Type) >= 0) {
                    returnArr.push('<a href="FileViewer.htm?FileClass=0&docRealName=' + currRow.data.RealName + '" target="_blank" onclick="return DocUsedLog(' + currRow.data.Id + ',0);">查看</a>');
                } else {
                    returnArr.push('<a href="FileDownload.aspx?fileId='+ currRow.data.Id + '" target="_blank" onclick="return DocUsedLog(' + currRow.data.Id + ',0);">下载</a>');
                }
                if ('doc,xls'.indexOf(currRow.data.Type) >= 0) {
                    var editStr = '<a href="#" onclick="return DocEdit(0,' + currRow.data.OwnerId + ',' + currRow.data.Pid + ',' + value + ',\'' + currRow.data.Type + '\',\'' + currRow.data.Name + '\',\'' + currRow.data.RealName + '\');">编辑</a>';
                    if (currRow.data.AuthLevel == 1) {//可写授权
                        returnArr.push(editStr);
                    }
                }
            }
            returnArr.reverse();
            return returnArr.join("&nbsp;&nbsp;");
        }
    }], autoHeight: true,hideHeaders: false, loadMask: true
});
DDStore.load();

DaiBan = new Ext.grid.GridPanel(
{
    id: 'daiBanGrid', border: false,store: DBStore = new Ext.data.Store(
    {
        url: '/Sign.mvc/GetSigningNodes', reader: new Ext.data.JsonReader(
        {
            id: 'daiBanReader', fields: ["FormNo", "ReqTypeName", "EmpId", "Name", "ReqDate"]
        })
    }), columns: [
    {
        header: '申请类别', width: 80, dataIndex: 'ReqTypeName',
        renderer: function (value, cellmeta, currRow) {
            return "<a href='#' onclick='return SignWin(\"" + currRow.data.FormNo + "\",true,true);'>" + value + "</a>";
        }
    }, {
        header: '申请人', width:60, dataIndex: 'Name'
    }, {
        header: '申请时间',width:150,hidden: false, dataIndex: 'ReqDate',
        renderer: function (value) {
            return DateParse(value);
        }
    }], autoHeight: true,hideHeaders: false, loadMask: true
});
DBStore.load();

DongTai = new Ext.grid.GridPanel(
{
    id: 'dongTaiGrid', border: false, store: DTStore = new Ext.data.Store(
    {
        url: '/Sign.mvc/GetSignStatus', reader: new Ext.data.JsonReader(
        {
            id: 'dongTaiReader', fields: ["FormNo", "ReqTypeName", "EmpId", "Name", "ReqDate", "StatusId", "CheckNode"]
        })
    }), columns: [
    {
        header: '申请类别', width: 80, dataIndex: 'ReqTypeName',
        renderer: function (value, cellmeta, currRow) {
            return "<a href='#' onclick='return SignWin(\"" + currRow.data.FormNo + "\",true,true);'>" + value + "</a>";
        }
    }, {
        header: '申请人', width: 60, dataIndex: 'Name'
    }, {
        header: '申请时间', width: 150, hidden: false, dataIndex: 'ReqDate',
        renderer: function (value) {
            return DateParse(value);
        }
    }, {
        header: '状态', dataIndex: 'StatusId',
        renderer: function (value, cellmeta, currRow) {
            var status;
            switch (value) {
                case 1: status = currRow.data.CheckNode; break;
                case 2: status = "通过"; break;
                case 3: status = currRow.data.CheckNode + " 退件"; break;
                default: status = "--"; break;
            }
            return status;
        }
    }], autoHeight: true,hideHeaders: false, loadMask: true
});
DTStore.load();

TiXing = new Ext.grid.GridPanel(
{
    id: 'tiXingGrid', border: false,store: TXStore = new Ext.data.Store(
    {
        url: '/Audition.mvc/GetRemind', reader: new Ext.data.JsonReader(
        {
            id: 'daiDuReader', fields: ["Affair", "RemindTime"]
        })
    }), columns: [
    {
        header: '事务', width:190, dataIndex: 'Affair',
        renderer: function (value, cellmeta, currRow) {
            return "<img src='../Content/images/home/notice2.gif' width='14px' height='14px'>" + value;
        }
    }, {
        header: '时间', width: 140, hidden: false, dataIndex: 'RemindTime',
        renderer: function (value) {
            return DateParse(value);
        }
    }], autoHeight: true,hideHeaders: false, loadMask: true
});
TXStore.load();

function refreshGrid() {
    GGstore.load();
    DDStore.load();
    DBStore.load();
    DTStore.load();
    TXStore.load();
    setTimeout(refreshGrid, 600000);
}
refreshGrid();

Swfu.BackMgr.mainview.Welcome = Ext.extend(Ext.TabPanel,
{
    initComponent: function () {
        Ext.apply(this,
        {
            activeTab: 0, autoScroll: true, tabPosition: 'button', layoutOnTabChange: true, items: [
            {
                layout: 'column', items: [
                {
                    columnWidth: .45, style: 'padding:5', border: false, tools: [{
                        id: 'refresh',
                        handler: function () {
                            GGstore.reload();
                        }
                    }],
                    title: '通知公告', bodyStyle: 'background-color:#FFFFFF', margins: '0', height: 192, frame: true, items: GongGao, autoScroll: true
                }, {
                    columnWidth: .55, style: 'padding:5', border: false, tools: [{
                        id: 'refresh',
                        handler: function () {
                            DDStore.reload();
                        }
                    }],
                    title: '待读文件', bodyStyle: 'background-color:#FFFFFF', margins: '0', height: 192, frame: true, items: DaiDu, autoScroll: true
                }, {
                    columnWidth: .29, style: 'padding:5', border: false, tools: [{
                        id: 'refresh',
                        handler: function () {
                            DBStore.reload();
                        }
                    }],
                    title: '申请签核', bodyStyle: 'background-color:#FFFFFF', margins: '0', height: 300, frame: true, items: DaiBan, autoScroll: true
                }, {
                    columnWidth: .38, style: 'padding:5', border: false, tools: [{
                        id: 'refresh',
                        handler: function () {
                            DTStore.reload();
                        }
                    }],
                    title: '申请状态', bodyStyle: 'background-color:#FFFFFF', margins: '0', height: 300, frame: true, items: DongTai, autoScroll: true
                }, {
                    columnWidth: .33, style: 'padding:5', border: false, tools: [{
                        id: 'refresh',
                        handler: function () {
                            TXStore.reload();
                        }
                    }],
                    title: '事务提醒', bodyStyle: 'background-color:#FFFFFF', margins: '0', height: 300, frame: true, items: TiXing, autoScroll: true
                }]
            }]
        });
        Swfu.BackMgr.mainview.Welcome.superclass.initComponent.apply(this, arguments);
    }
});
Ext.reg('Welcome', Swfu.BackMgr.mainview.Welcome);